package Servlet.StudentServlet;

import Entity.SelectCourse;
import Service.StudentService.StudentService;
import Util.ReadJsonString;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import sun.dc.pr.PRError;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
/*
负责学生 添加审核通过的课程信息 数据接口
 */
@WebServlet(value = "/studentAddCourse")
public class StudentAddCourse extends HttpServlet {

    private StudentService studentService = new StudentService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        /*
        前端发送Json数据 需要从request 流中解析成Json处理
         */
        String json = ReadJsonString.readJSONString(request);

        /*
        json文本解析成Json对象
         */
        List<SelectCourse> selectCourseList = JSON.parseArray(json,SelectCourse.class);


        int successCount = studentService.insertSelectCourse(selectCourseList);
        PrintWriter out = response.getWriter();
        out.print(successCount);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
